﻿namespace HRM.CORE
{
    using DevExpress.Utils;
    using DevExpress.XtraBars;
    using DevExpress.XtraEditors;
    using DevExpress.XtraTreeList;
    using DevExpress.XtraTreeList.Columns;
    using DevExpress.XtraTreeList.Nodes;
    using APP.HELPER;
    using Common.Class; using APP.HELPER.Utils.Language; using Security.Security; using Dictionary.ERP;
    using Dictionary;
    using HRM.CORE;
    
    
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;
    using Security.ERP;

    public class xucOrganization : Common.xucBase
    {
        private BarDockControl barDockControlBottom;
        private BarDockControl barDockControlLeft;
        private BarDockControl barDockControlRight;
        private BarDockControl barDockControlTop;
        private BarManager barManager1;
        private BarButtonItem bbiBranchAdd;
        private BarButtonItem bbiBranchDelete;
        private BarButtonItem bbiBranchEdit;
        private BarButtonItem bbiDepartmentAdd;
        private BarButtonItem bbiDepartmentDelete;
        private BarButtonItem bbiDepartmentEdit;
        private BarButtonItem bbiGroupAdd;
        private BarButtonItem bbiGroupDelete;
        private BarButtonItem bbiGroupEdit;
        private BarSubItem bbiOrtherAdd1;
        private BarSubItem bbiOrtherAdd2;
        private BarSubItem bbiOrtherAdd3;
        private BarButtonItem bbiReload;
        private BarButtonItem bbiTransferBranch;
        private BarButtonItem bbiTransferDepartment;
        private BarButtonItem bbiTransferGroup;
        private Organization cls;
        private TreeListColumn colTitle;
        private IContainer components = null;
        private DataTable dt;
        public DevExpress.Utils.ImageCollection imageCollection2;
        private DevExpress.Utils.ImageCollection imgTree;
        private string m_CompanyName = "";
        private bool m_IsAll = false;
        private Point m_Point;
        private int m_Status = 2;
        private PopupMenu ppBranch;
        private PopupMenu ppCompany;
        private PopupMenu ppDepartment;
        private PopupMenu ppEmployee;
        private PopupMenu ppGroup;
        private TreeList treeList1;

        public event SelectedEventHander Selected;

        public event UpdatedEventHander Updated;

        public xucOrganization()
        {
            this.InitializeComponent();
            this.InitMultiLanguages();
            base.Load += new EventHandler(this.xucOrganization_Load);
        }

        private void AddEmployeeToDataTable(DataTable dt, string Place, string Code)
        {
            DataTable table;
            HRM_EMPLOYEE hrm_employee = new HRM_EMPLOYEE();
            if (Place == "Branch")
            {
                table = hrm_employee.GetListCurrentNow(1, Code, -1);
            }
            else if (Place == "Department")
            {
                table = hrm_employee.GetListCurrentNow(2, Code, -1);
            }
            else
            {
                table = hrm_employee.GetListCurrentNow(3, Code, -1);
            }
            foreach (DataRow row in table.Rows)
            {
                if ((bool) row["Sex"])
                {
                    if (((int) row["Status"]) != 3)
                    {
                        dt.Rows.Add(new object[] { row["EmployeeCode"].ToString(), row["FirstName"].ToString() + " " + row["LastName"].ToString(), row["GroupCode"].ToString(), "Employee", 4 });
                    }
                    else
                    {
                        dt.Rows.Add(new object[] { row["EmployeeCode"].ToString(), row["FirstName"].ToString() + " " + row["LastName"].ToString(), row["GroupCode"].ToString(), "Employee", 6 });
                    }
                }
                else if (((int) row["Status"]) != 3)
                {
                    dt.Rows.Add(new object[] { row["EmployeeCode"].ToString(), row["FirstName"].ToString() + " " + row["LastName"].ToString(), row["GroupCode"].ToString(), "Employee", 5 });
                }
                else
                {
                    dt.Rows.Add(new object[] { row["EmployeeCode"].ToString(), row["FirstName"].ToString() + " " + row["LastName"].ToString(), row["GroupCode"].ToString(), "Employee", 7 });
                }
            }
        }

        private void bbiBranchAdd_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MyRule.IsAdd("bbiBranch"))
            {
                xfmBranchAdd add = new xfmBranchAdd(Actions.Add);
                add.Added += new xfmBranchAdd.AddedEventHander(this.frm_Added);
                add.ShowDialog();
            }
        }

        private void bbiBranchDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MyRule.IsDelete("bbiBranch") && (!ClsOption.System2.IsQuestion || (XtraMessageBox.Show("Bạn c\x00f3 muốn x\x00f3a kh\x00f4ng?", "Th\x00f4ng b\x00e1o", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.No)))
            {
                HRM_BRANCH hrm_branch = new HRM_BRANCH();
                string str = "";
                object branchCode = null;
                branchCode = this.cls.BranchCode;
                if (branchCode != null)
                {
                    SYS_LOG.Insert("Danh S\x00e1ch Chi Nh\x00e1nh", "Xo\x00e1", branchCode.ToString());
                    base.SetWaitDialogCaption("Đang x\x00f3a...");
                    HRM_EMPLOYEE hrm_employee = new HRM_EMPLOYEE();
                    DataTable table = hrm_employee.GetList(1, branchCode.ToString(), -1, System.DateTime.Now, System.DateTime.Now);
                    foreach (DataRow row in table.Rows)
                    {
                        base.SetWaitDialogCaption("Đang x\x00f3a..." + row["FirstName"].ToString() + " " + row["LastName"].ToString());
                        hrm_employee.Delete(row["EmployeeCode"].ToString());
                    }
                    str = hrm_branch.Delete(branchCode.ToString());
                    if (str == "OK")
                    {
                        this.treeList1.Nodes.Remove(this.treeList1.FocusedNode);
                    }
                    else if (str != "OK")
                    {
                        MessageBox.Show("Th\x00f4ng tin kh\x00f4ng được x\x00f3a\n" + str, "Th\x00f4ng b\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    this.DoHide();
                }
            }
        }

        private void bbiBranchEdit_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MyRule.IsAccess("bbiBranch"))
            {
                HRM_BRANCH item = new HRM_BRANCH();
                object branchCode = this.cls.BranchCode;
                if (branchCode != null)
                {
                    base.SetWaitDialogCaption("Đang kiểm tra dữ liệu....");
                    if (item.Get(branchCode.ToString()) != "OK")
                    {
                        this.DoHide();
                        XtraMessageBox.Show("Dữ liệu kh\x00f4ng tồn tại", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        this.DoHide();
                        xfmBranchAdd add = new xfmBranchAdd(Actions.Update, item);
                        add.Updated += new xfmBranchAdd.UpdatedEventHander(this.frm_Updated);
                        add.ShowDialog();
                    }
                }
            }
        }

        private void bbiDepartmentAdd_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MyRule.IsAdd("bbiDepartment"))
            {
                xfmDepartmentAdd add = new xfmDepartmentAdd(Actions.Add, this.cls.BranchCode);
                add.Added += new xfmDepartmentAdd.AddedEventHander(this.frm_Added);
                add.ShowDialog();
            }
        }

        private void bbiDepartmentDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MyRule.IsDelete("bbiDepartment") && (!ClsOption.System2.IsQuestion || (XtraMessageBox.Show("Bạn c\x00f3 muốn x\x00f3a kh\x00f4ng?", "Th\x00f4ng b\x00e1o", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.No)))
            {
                HRM_DEPARTMENT hrm_department = new HRM_DEPARTMENT();
                string str = "";
                object departmentCode = null;
                departmentCode = this.cls.DepartmentCode;
                if (departmentCode != null)
                {
                    SYS_LOG.Insert("Danh S\x00e1ch Ph\x00f2ng Ban", "Xo\x00e1", departmentCode.ToString());
                    base.SetWaitDialogCaption("Đang x\x00f3a...");
                    HRM_EMPLOYEE hrm_employee = new HRM_EMPLOYEE();
                    DataTable table = hrm_employee.GetList(2, departmentCode.ToString(), -1, System.DateTime.Now, System.DateTime.Now);
                    foreach (DataRow row in table.Rows)
                    {
                        base.SetWaitDialogCaption("Đang x\x00f3a..." + row["FirstName"].ToString() + " " + row["LastName"].ToString());
                        hrm_employee.Delete(row["EmployeeCode"].ToString());
                    }
                    str = hrm_department.Delete(departmentCode.ToString());
                    if (str == "OK")
                    {
                        TreeListNode focusedNode = this.treeList1.FocusedNode;
                        this.treeList1.Nodes.Remove(focusedNode);
                    }
                    else if (str != "OK")
                    {
                        MessageBox.Show("Th\x00f4ng tin kh\x00f4ng được x\x00f3a\n" + str, "Th\x00f4ng b\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    this.DoHide();
                }
            }
        }

        private void bbiDepartmentEdit_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MyRule.IsAccess("bbiDepartment"))
            {
                HRM_DEPARTMENT item = new HRM_DEPARTMENT();
                object departmentCode = this.cls.DepartmentCode;
                if (departmentCode != null)
                {
                    base.SetWaitDialogCaption("Đang kiểm tra dữ liệu....");
                    if (item.Get(departmentCode.ToString()) != "OK")
                    {
                        this.DoHide();
                        XtraMessageBox.Show("Dữ liệu kh\x00f4ng tồn tại", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        this.DoHide();
                        xfmDepartmentAdd add = new xfmDepartmentAdd(Actions.Update, item);
                        add.Updated += new xfmDepartmentAdd.UpdatedEventHander(this.frm_Updated);
                        add.ShowDialog();
                    }
                }
            }
        }

        private void bbiGroupAdd_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MyRule.IsAdd("bbiGroup"))
            {
                Dictionary.xfmGroupAdd add = new Dictionary.xfmGroupAdd(Actions.Add, this.cls.BranchCode, this.cls.DepartmentCode);
                add.Added += new Dictionary.xfmGroupAdd.AddedEventHander(this.frm_Added);
                add.ShowDialog();
            }
        }

        private void bbiGroupDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MyRule.IsDelete("bbiGroup") && (!ClsOption.System2.IsQuestion || (XtraMessageBox.Show("Bạn c\x00f3 muốn x\x00f3a kh\x00f4ng?", "Th\x00f4ng b\x00e1o", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.No)))
            {
                HRM_GROUP hrm_group = new HRM_GROUP();
                string str = "";
                object groupCode = null;
                groupCode = this.cls.GroupCode;
                if (groupCode != null)
                {
                    SYS_LOG.Insert("Danh S\x00e1ch Tổ Nh\x00f3m", "Xo\x00e1", groupCode.ToString());
                    base.SetWaitDialogCaption("Đang x\x00f3a...");
                    HRM_EMPLOYEE hrm_employee = new HRM_EMPLOYEE();
                    DataTable table = hrm_employee.GetList(3, groupCode.ToString(), -1, System.DateTime.Now, System.DateTime.Now);
                    foreach (DataRow row in table.Rows)
                    {
                        base.SetWaitDialogCaption("Đang x\x00f3a..." + row["FirstName"].ToString() + " " + row["LastName"].ToString());
                        hrm_employee.Delete(row["EmployeeCode"].ToString());
                    }
                    str = hrm_group.Delete(groupCode.ToString());
                    if (str == "OK")
                    {
                        this.treeList1.Nodes.Remove(this.treeList1.FocusedNode);
                    }
                    else if (str != "OK")
                    {
                        MessageBox.Show("Th\x00f4ng tin kh\x00f4ng được x\x00f3a\n" + str, "Th\x00f4ng b\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    this.DoHide();
                }
            }
        }

        private void bbiGroupEdit_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MyRule.IsAccess("bbiGroup"))
            {
                HRM_GROUP item = new HRM_GROUP();
                object groupCode = this.cls.GroupCode;
                if (groupCode != null)
                {
                    base.SetWaitDialogCaption("Đang kiểm tra dữ liệu....");
                    if (item.Get(groupCode.ToString()) != "OK")
                    {
                        this.DoHide();
                        XtraMessageBox.Show("Dữ liệu kh\x00f4ng tồn tại", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        this.DoHide();
                        Dictionary.xfmGroupAdd add = new Dictionary.xfmGroupAdd(Actions.Update, item);
                        add.Updated += new Dictionary.xfmGroupAdd.UpdatedEventHander(this.frm_Updated);
                        add.ShowDialog();
                    }
                }
            }
        }

        private void bbiReload_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Reload();
        }

        private void bbiTransferBranch_ItemClick(object sender, ItemClickEventArgs e)
        {
            HRM_EMPLOYEE hrm_employee = new HRM_EMPLOYEE();
            xfmTransfer transfer = new xfmTransfer(hrm_employee.GetListCurrentNow(1, this.cls.BranchCode, -1));
            transfer.Success += o => this.Reload();
            transfer.ShowDialog();
        }

        private void bbiTransferDepartment_ItemClick(object sender, ItemClickEventArgs e)
        {
            HRM_EMPLOYEE hrm_employee = new HRM_EMPLOYEE();
            xfmTransfer transfer = new xfmTransfer(hrm_employee.GetListCurrentNow(2, this.cls.DepartmentCode, -1));
            transfer.Success += o => this.Reload();
            transfer.ShowDialog();
        }

        private void bbiTransferGroup_ItemClick(object sender, ItemClickEventArgs e)
        {
            HRM_EMPLOYEE hrm_employee = new HRM_EMPLOYEE();
            xfmTransfer transfer = new xfmTransfer(hrm_employee.GetListCurrentNow(3, this.cls.GroupCode, -1));
            transfer.Success += o => this.Reload();
            transfer.ShowDialog();
        }

        public void DeleteNode(TreeListNode Node)
        {
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void frm_Added(object sender, HRM_BRANCH Item)
        {
            foreach (TreeListNode node in this.treeList1.Nodes)
            {
                if (int.Parse(node.GetValue("ImageIndex").ToString()) == 0)
                {
                    TreeListNode node2 = this.treeList1.AppendNode(new object[] { Item.BranchCode, Item.BranchName + this.StringQuantity(0, 0), node.GetValue("ID").ToString(), "Branch", 0, 0, 1 }, node);
                }
            }
        }

        private void frm_Added(object sender, HRM_DEPARTMENT Item)
        {
            this.RaiseUpdatedEventHander();
        }

        private void frm_Added(object sender, HRM_GROUP Item)
        {
            this.RaiseUpdatedEventHander();
        }

        private void frm_Updated(object sender, HRM_BRANCH Item)
        {
            TreeListNode focusedNode = this.treeList1.FocusedNode;
            focusedNode.SetValue("Name", Item.BranchName + this.StringQuantity(int.Parse(focusedNode.GetValue("FactQuantity").ToString()), int.Parse(focusedNode.GetValue("Quantity").ToString())));
        }

        private void frm_Updated(object sender, HRM_DEPARTMENT Item)
        {
            this.RaiseUpdatedEventHander();
        }

        private void frm_Updated(object sender, HRM_GROUP Item)
        {
            this.RaiseUpdatedEventHander();
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xucOrganization));
            this.imgTree = new DevExpress.Utils.ImageCollection(this.components);
            this.treeList1 = new TreeList();
            this.colTitle = new TreeListColumn();
            this.barManager1 = new BarManager(this.components);
            this.barDockControlTop = new BarDockControl();
            this.barDockControlBottom = new BarDockControl();
            this.barDockControlLeft = new BarDockControl();
            this.barDockControlRight = new BarDockControl();
            this.imageCollection2 = new DevExpress.Utils.ImageCollection(this.components);
            this.bbiBranchAdd = new BarButtonItem();
            this.bbiBranchEdit = new BarButtonItem();
            this.bbiBranchDelete = new BarButtonItem();
            this.bbiDepartmentEdit = new BarButtonItem();
            this.bbiDepartmentAdd = new BarButtonItem();
            this.bbiDepartmentDelete = new BarButtonItem();
            this.bbiGroupEdit = new BarButtonItem();
            this.bbiGroupAdd = new BarButtonItem();
            this.bbiGroupDelete = new BarButtonItem();
            this.bbiOrtherAdd1 = new BarSubItem();
            this.bbiOrtherAdd2 = new BarSubItem();
            this.bbiOrtherAdd3 = new BarSubItem();
            this.bbiTransferDepartment = new BarButtonItem();
            this.bbiTransferGroup = new BarButtonItem();
            this.bbiReload = new BarButtonItem();
            this.ppCompany = new PopupMenu(this.components);
            this.ppBranch = new PopupMenu(this.components);
            this.ppDepartment = new PopupMenu(this.components);
            this.ppGroup = new PopupMenu(this.components);
            this.ppEmployee = new PopupMenu(this.components);
            this.bbiTransferBranch = new BarButtonItem();
            this.imgTree.BeginInit();
            this.treeList1.BeginInit();
            this.barManager1.BeginInit();
            this.imageCollection2.BeginInit();
            this.ppCompany.BeginInit();
            this.ppBranch.BeginInit();
            this.ppDepartment.BeginInit();
            this.ppGroup.BeginInit();
            this.ppEmployee.BeginInit();
            base.SuspendLayout();
            this.imgTree.ImageStream = (ImageCollectionStreamer) manager.GetObject("imgTree.ImageStream");
            this.imgTree.Images.SetKeyName(0, "1280288152_building.png");
            this.imgTree.Images.SetKeyName(1, "P_MyServer_16x16.png");
            this.imgTree.Images.SetKeyName(2, "BO_Address.png");
            this.imgTree.Images.SetKeyName(3, "1280287512_User group.png");
            this.imgTree.Images.SetKeyName(4, "male.png");
            this.imgTree.Images.SetKeyName(5, "user_woman.png");
            this.imgTree.Images.SetKeyName(6, "male1.png");
            this.imgTree.Images.SetKeyName(7, "female1.png");
            this.treeList1.Appearance.FocusedCell.BackColor = Color.Orange;
            this.treeList1.Appearance.FocusedCell.BackColor2 = Color.White;
            this.treeList1.Appearance.FocusedCell.GradientMode = LinearGradientMode.BackwardDiagonal;
            this.treeList1.Appearance.FocusedCell.Options.UseBackColor = true;
            this.treeList1.Columns.AddRange(new TreeListColumn[] { this.colTitle });
            this.treeList1.Dock = DockStyle.Fill;
            this.treeList1.Location = new Point(0, 0);
            this.treeList1.Name = "treeList1";
            this.treeList1.OptionsBehavior.PopulateServiceColumns = true;
            this.treeList1.OptionsView.ShowHorzLines = false;
            this.treeList1.OptionsView.ShowVertLines = false;
            this.treeList1.SelectImageList = this.imgTree;
            this.treeList1.Size = new Size(0x12a, 0x22a);
            this.treeList1.TabIndex = 1;
            this.treeList1.MouseDown += new MouseEventHandler(this.xucOrganization_MouseDown);
            this.treeList1.FocusedNodeChanged += new FocusedNodeChangedEventHandler(this.treeList1_FocusedNodeChanged);
            this.treeList1.GetSelectImage += new GetSelectImageEventHandler(this.treeList1_GetSelectImage);
            this.colTitle.Caption = "Cơ cấu tổ chức";
            this.colTitle.FieldName = "Name";
            this.colTitle.Name = "colTitle";
            this.colTitle.OptionsColumn.AllowEdit = false;
            this.colTitle.OptionsColumn.ReadOnly = true;
            this.colTitle.Visible = true;
            this.colTitle.VisibleIndex = 0;
            this.barManager1.DockControls.Add(this.barDockControlTop);
            this.barManager1.DockControls.Add(this.barDockControlBottom);
            this.barManager1.DockControls.Add(this.barDockControlLeft);
            this.barManager1.DockControls.Add(this.barDockControlRight);
            this.barManager1.Form = this;
            this.barManager1.Images = this.imageCollection2;
            this.barManager1.Items.AddRange(new BarItem[] { this.bbiBranchAdd, this.bbiBranchEdit, this.bbiBranchDelete, this.bbiDepartmentEdit, this.bbiDepartmentAdd, this.bbiDepartmentDelete, this.bbiGroupEdit, this.bbiGroupAdd, this.bbiGroupDelete, this.bbiOrtherAdd1, this.bbiOrtherAdd2, this.bbiOrtherAdd3, this.bbiTransferDepartment, this.bbiTransferGroup, this.bbiReload, this.bbiTransferBranch });
            this.barManager1.MaxItemId = 0x1a;
            this.imageCollection2.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection2.ImageStream");
            this.imageCollection2.Images.SetKeyName(0x3d, "Vista (35).ico");
            this.imageCollection2.Images.SetKeyName(0x3e, "Security.ico");
            this.imageCollection2.Images.SetKeyName(0x3f, "RibbonPrintPreview_DocumentMapLarge.png");
            this.imageCollection2.Images.SetKeyName(0x40, "11.png");
            this.imageCollection2.Images.SetKeyName(0x41, "Sua.png");
            this.imageCollection2.Images.SetKeyName(0x42, "Them.png");
            this.imageCollection2.Images.SetKeyName(0x43, "PhanQuyen.png");
            this.imageCollection2.Images.SetKeyName(0x44, "11.png");
            this.imageCollection2.Images.SetKeyName(0x45, "plus.png");
            this.bbiBranchAdd.Caption = "Th\x00eam chi nh\x00e1nh";
            this.bbiBranchAdd.Id = 4;
            this.bbiBranchAdd.ImageIndex = 0x45;
            this.bbiBranchAdd.Name = "bbiBranchAdd";
            this.bbiBranchAdd.ItemClick += new ItemClickEventHandler(this.bbiBranchAdd_ItemClick);
            this.bbiBranchEdit.Caption = "Sửa chi nh\x00e1nh";
            this.bbiBranchEdit.Id = 5;
            this.bbiBranchEdit.ImageIndex = 14;
            this.bbiBranchEdit.Name = "bbiBranchEdit";
            this.bbiBranchEdit.ItemClick += new ItemClickEventHandler(this.bbiBranchEdit_ItemClick);
            this.bbiBranchDelete.Caption = "X\x00f3a chi nh\x00e1nh n\x00e0y";
            this.bbiBranchDelete.Id = 6;
            this.bbiBranchDelete.ImageIndex = 13;
            this.bbiBranchDelete.Name = "bbiBranchDelete";
            this.bbiBranchDelete.ItemClick += new ItemClickEventHandler(this.bbiBranchDelete_ItemClick);
            this.bbiDepartmentEdit.Caption = "Sửa ph\x00f2ng ban";
            this.bbiDepartmentEdit.Id = 10;
            this.bbiDepartmentEdit.ImageIndex = 14;
            this.bbiDepartmentEdit.Name = "bbiDepartmentEdit";
            this.bbiDepartmentEdit.ItemClick += new ItemClickEventHandler(this.bbiDepartmentEdit_ItemClick);
            this.bbiDepartmentAdd.Caption = "Th\x00eam ph\x00f2ng ban";
            this.bbiDepartmentAdd.Id = 11;
            this.bbiDepartmentAdd.ImageIndex = 0x45;
            this.bbiDepartmentAdd.Name = "bbiDepartmentAdd";
            this.bbiDepartmentAdd.ItemClick += new ItemClickEventHandler(this.bbiDepartmentAdd_ItemClick);
            this.bbiDepartmentDelete.Caption = "X\x00f3a ph\x00f2ng ban";
            this.bbiDepartmentDelete.Id = 12;
            this.bbiDepartmentDelete.ImageIndex = 13;
            this.bbiDepartmentDelete.Name = "bbiDepartmentDelete";
            this.bbiDepartmentDelete.ItemClick += new ItemClickEventHandler(this.bbiDepartmentDelete_ItemClick);
            this.bbiGroupEdit.Caption = "Sửa tổ nh\x00f3m";
            this.bbiGroupEdit.Id = 13;
            this.bbiGroupEdit.ImageIndex = 14;
            this.bbiGroupEdit.Name = "bbiGroupEdit";
            this.bbiGroupEdit.ItemClick += new ItemClickEventHandler(this.bbiGroupEdit_ItemClick);
            this.bbiGroupAdd.Caption = "Th\x00eam tổ nh\x00f3m";
            this.bbiGroupAdd.Id = 14;
            this.bbiGroupAdd.ImageIndex = 0x45;
            this.bbiGroupAdd.Name = "bbiGroupAdd";
            this.bbiGroupAdd.ItemClick += new ItemClickEventHandler(this.bbiGroupAdd_ItemClick);
            this.bbiGroupDelete.Caption = "X\x00f3a tổ nh\x00f3m";
            this.bbiGroupDelete.Id = 15;
            this.bbiGroupDelete.ImageIndex = 13;
            this.bbiGroupDelete.Name = "bbiGroupDelete";
            this.bbiGroupDelete.ItemClick += new ItemClickEventHandler(this.bbiGroupDelete_ItemClick);
            this.bbiOrtherAdd1.Caption = "Th\x00eam kh\x00e1c";
            this.bbiOrtherAdd1.Id = 0x11;
            this.bbiOrtherAdd1.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(this.bbiDepartmentAdd), new LinkPersistInfo(this.bbiGroupAdd) });
            this.bbiOrtherAdd1.Name = "bbiOrtherAdd1";
            this.bbiOrtherAdd2.Caption = "Th\x00eam kh\x00e1c";
            this.bbiOrtherAdd2.Id = 0x12;
            this.bbiOrtherAdd2.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(this.bbiBranchAdd), new LinkPersistInfo(this.bbiGroupAdd) });
            this.bbiOrtherAdd2.Name = "bbiOrtherAdd2";
            this.bbiOrtherAdd3.Caption = "Th\x00eam kh\x00e1c";
            this.bbiOrtherAdd3.Id = 0x13;
            this.bbiOrtherAdd3.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(this.bbiBranchAdd), new LinkPersistInfo(this.bbiDepartmentAdd) });
            this.bbiOrtherAdd3.Name = "bbiOrtherAdd3";
            this.bbiTransferDepartment.Caption = "Chuyển NV trong ph\x00f2ng ban";
            this.bbiTransferDepartment.Id = 20;
            this.bbiTransferDepartment.Name = "bbiTransferDepartment";
            this.bbiTransferDepartment.ItemClick += new ItemClickEventHandler(this.bbiTransferDepartment_ItemClick);
            this.bbiTransferGroup.Caption = "Chuyển NV trong tổ nh\x00f3m";
            this.bbiTransferGroup.Id = 0x15;
            this.bbiTransferGroup.Name = "bbiTransferGroup";
            this.bbiTransferGroup.ItemClick += new ItemClickEventHandler(this.bbiTransferGroup_ItemClick);
            this.bbiReload.Caption = "Nạp lại";
            this.bbiReload.Id = 0x16;
            this.bbiReload.ImageIndex = 0x2a;
            this.bbiReload.Name = "bbiReload";
            this.bbiReload.ItemClick += new ItemClickEventHandler(this.bbiReload_ItemClick);
            this.ppCompany.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(this.bbiBranchAdd), new LinkPersistInfo(this.bbiDepartmentAdd), new LinkPersistInfo(this.bbiGroupAdd), new LinkPersistInfo(BarLinkUserDefines.PaintStyle, this.bbiReload, "", true, true, true, 0, null, BarItemPaintStyle.CaptionGlyph) });
            this.ppCompany.Manager = this.barManager1;
            this.ppCompany.Name = "ppCompany";
            this.ppBranch.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(this.bbiBranchEdit), new LinkPersistInfo(this.bbiBranchAdd, true), new LinkPersistInfo(this.bbiOrtherAdd1), new LinkPersistInfo(this.bbiTransferBranch), new LinkPersistInfo(this.bbiBranchDelete, true), new LinkPersistInfo(this.bbiReload) });
            this.ppBranch.Manager = this.barManager1;
            this.ppBranch.Name = "ppBranch";
            this.ppDepartment.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(this.bbiDepartmentEdit), new LinkPersistInfo(this.bbiDepartmentAdd, true), new LinkPersistInfo(this.bbiOrtherAdd2), new LinkPersistInfo(this.bbiTransferDepartment), new LinkPersistInfo(this.bbiDepartmentDelete, true), new LinkPersistInfo(this.bbiReload) });
            this.ppDepartment.Manager = this.barManager1;
            this.ppDepartment.Name = "ppDepartment";
            this.ppGroup.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(this.bbiGroupEdit), new LinkPersistInfo(this.bbiGroupAdd, true), new LinkPersistInfo(this.bbiOrtherAdd3), new LinkPersistInfo(this.bbiTransferGroup), new LinkPersistInfo(this.bbiGroupDelete, true), new LinkPersistInfo(this.bbiReload) });
            this.ppGroup.Manager = this.barManager1;
            this.ppGroup.Name = "ppGroup";
            this.ppEmployee.Manager = this.barManager1;
            this.ppEmployee.Name = "ppEmployee";
            this.bbiTransferBranch.Caption = "Chuyển NV trong chi nh\x00e1nh n\x00e0y";
            this.bbiTransferBranch.Id = 0x19;
            this.bbiTransferBranch.Name = "bbiTransferBranch";
            this.bbiTransferBranch.ItemClick += new ItemClickEventHandler(this.bbiTransferBranch_ItemClick);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.treeList1);
            base.Controls.Add(this.barDockControlLeft);
            base.Controls.Add(this.barDockControlRight);
            base.Controls.Add(this.barDockControlBottom);
            base.Controls.Add(this.barDockControlTop);
            base.Name = "xucOrganization";
            base.Size = new Size(0x12a, 0x22a);
            base.MouseDown += new MouseEventHandler(this.xucOrganization_MouseDown);
            this.imgTree.EndInit();
            this.treeList1.EndInit();
            this.barManager1.EndInit();
            this.imageCollection2.EndInit();
            this.ppCompany.EndInit();
            this.ppBranch.EndInit();
            this.ppDepartment.EndInit();
            this.ppGroup.EndInit();
            this.ppEmployee.EndInit();
            base.ResumeLayout(false);
        }

        private void InitMultiLanguages()
        {
            this.colTitle.Caption = MultiLanguages.GetString("tbl_Organization", "Organization", this.colTitle.Caption);
            this.bbiBranchAdd.Caption = MultiLanguages.GetString("tbl_Organization", "BranchAdd", this.bbiBranchAdd.Caption);
            this.bbiBranchEdit.Caption = MultiLanguages.GetString("tbl_Organization", "BranchEdit", this.bbiBranchEdit.Caption);
            this.bbiBranchDelete.Caption = MultiLanguages.GetString("tbl_Organization", "BranchDelete", this.bbiBranchDelete.Caption);
            this.bbiDepartmentAdd.Caption = MultiLanguages.GetString("tbl_Organization", "DepartmentAdd", this.bbiDepartmentAdd.Caption);
            this.bbiDepartmentEdit.Caption = MultiLanguages.GetString("tbl_Organization", "DepartmentEdit", this.bbiDepartmentEdit.Caption);
            this.bbiDepartmentDelete.Caption = MultiLanguages.GetString("tbl_Organization", "DepartmentDelete", this.bbiDepartmentDelete.Caption);
            this.bbiGroupAdd.Caption = MultiLanguages.GetString("tbl_Organization", "GroupAdd", this.bbiGroupAdd.Caption);
            this.bbiGroupEdit.Caption = MultiLanguages.GetString("tbl_Organization", "GroupEdit", this.bbiGroupEdit.Caption);
            this.bbiGroupDelete.Caption = MultiLanguages.GetString("tbl_Organization", "GroupDelete", this.bbiGroupDelete.Caption);
            this.bbiOrtherAdd1.Caption = MultiLanguages.GetString("tbl_Organization", "OrtherAdd", this.bbiOrtherAdd1.Caption);
            this.bbiOrtherAdd2.Caption = MultiLanguages.GetString("tbl_Organization", "OrtherAdd", this.bbiOrtherAdd2.Caption);
            this.bbiOrtherAdd3.Caption = MultiLanguages.GetString("tbl_Organization", "OrtherAdd", this.bbiOrtherAdd3.Caption);
            this.bbiTransferDepartment.Caption = MultiLanguages.GetString("tbl_Organization", "TransferDepartment", this.bbiTransferDepartment.Caption);
            this.bbiTransferGroup.Caption = MultiLanguages.GetString("tbl_Organization", "TransferGroup", this.bbiTransferGroup.Caption);
            this.bbiReload.Caption = MultiLanguages.GetString("tbl_Organization", "Refresh", this.bbiReload.Caption);
        }

        public void InsertNodeByLevelCode(int Level, string Code)
        {
        }

        public void LoadAllData()
        {
            this.m_IsAll = true;
            this.m_Status = 2;
            this.LoadTreeList();
        }

        public void LoadAllData(int Status)
        {
            this.m_IsAll = true;
            this.m_Status = Status;
            this.LoadTreeList();
        }

        public void LoadData()
        {
            this.m_IsAll = false;
            this.m_Status = 2;
            this.LoadTreeList();
        }

        public void LoadData(int Status)
        {
            this.m_IsAll = false;
            this.m_Status = Status;
            this.LoadTreeList();
        }

        private void LoadTreeList()
        {
            DataTable listByBranch;
            HRM_GROUP hrm_group;
            DataTable listByDepartment;
            //if (MyInfo.GetInfo() == "OK")
            {
                this.m_CompanyName = "";// MyInfo.Company;
            }
            this.dt = new DataTable();
            this.dt.Columns.Add("ID");
            this.dt.Columns.Add("Name");
            this.dt.Columns.Add("ParentID");
            this.dt.Columns.Add("Type");
            this.dt.Columns.Add("FactQuantity");
            this.dt.Columns.Add("Quantity");
            this.dt.Columns.Add("ImageIndex");
            if (MyLogin.Level == 0)
            {
                this.dt.Rows.Add(new object[] { "All", this.m_CompanyName, "", "Company", 0, 0, 0 });
                int factQuantity = 0;
                int quantity = 0;
                DataTable list = new HRM_BRANCH().GetList();
                foreach (DataRow row in list.Rows)
                {
                    this.dt.Rows.Add(new object[] { row["BranchCode"].ToString(), row["BranchName"].ToString() + this.StringQuantity(row), "All", "Branch", int.Parse(row["FactQuantity"].ToString()), int.Parse(row["Quantity"].ToString()), 1 });
                    factQuantity += int.Parse(row["FactQuantity"].ToString());
                    quantity += int.Parse(row["Quantity"].ToString());
                    HRM_DEPARTMENT hrm_department = new HRM_DEPARTMENT();
                    listByBranch = hrm_department.GetListByBranch(row["BranchCode"].ToString());
                    foreach (DataRow row2 in listByBranch.Rows)
                    {
                        this.dt.Rows.Add(new object[] { row2["DepartmentCode"].ToString(), row2["DepartmentName"].ToString() + this.StringQuantity(row2), row["BranchCode"].ToString(), "Department", int.Parse(row2["FactQuantity"].ToString()), int.Parse(row2["Quantity"].ToString()), 2 });
                        hrm_group = new HRM_GROUP();
                        listByDepartment = hrm_group.GetListByDepartment(row2["DepartmentCode"].ToString());
                        foreach (DataRow row3 in listByDepartment.Rows)
                        {
                            this.dt.Rows.Add(new object[] { row3["GroupCode"].ToString(), row3["GroupName"].ToString() + this.StringQuantity(row3), row3["DepartmentCode"].ToString(), "Group", int.Parse(row3["FactQuantity"].ToString()), int.Parse(row3["Quantity"].ToString()), 3 });
                            if (this.m_IsAll)
                            {
                                this.AddEmployeeToDataTable(this.dt, "Group", row3["GroupCode"].ToString());
                            }
                        }
                    }
                }
                this.dt.Rows[0]["Name"] = this.dt.Rows[0]["Name"].ToString() + this.StringQuantity(factQuantity, quantity);
                this.dt.Rows[0]["FactQuantity"] = factQuantity;
                this.dt.Rows[0]["Quantity"] = quantity;
            }
            else if (MyLogin.Level == 1)
            {
                HRM_BRANCH hrm_branch2 = new HRM_BRANCH();
                hrm_branch2.Get(MyLogin.Code);
                this.dt.Rows.Add(new object[] { hrm_branch2.BranchCode, hrm_branch2.BranchName + this.StringQuantity(hrm_branch2.FactQuantity, hrm_branch2.Quantity), "", "Branch", hrm_branch2.FactQuantity, hrm_branch2.Quantity, 1 });
                listByBranch = new HRM_DEPARTMENT().GetListByBranch(hrm_branch2.BranchCode);
                foreach (DataRow row2 in listByBranch.Rows)
                {
                    this.dt.Rows.Add(new object[] { row2["DepartmentCode"].ToString(), row2["DepartmentName"].ToString() + this.StringQuantity(row2), hrm_branch2.BranchCode, "Department", int.Parse(row2["FactQuantity"].ToString()), int.Parse(row2["Quantity"].ToString()), 2 });
                    hrm_group = new HRM_GROUP();
                    listByDepartment = hrm_group.GetListByDepartment(row2["DepartmentCode"].ToString());
                    foreach (DataRow row3 in listByDepartment.Rows)
                    {
                        this.dt.Rows.Add(new object[] { row3["GroupCode"].ToString(), row3["GroupName"].ToString() + this.StringQuantity(row3), row3["DepartmentCode"].ToString(), "Group", int.Parse(row3["FactQuantity"].ToString()), int.Parse(row3["Quantity"].ToString()), 3 });
                        if (this.m_IsAll)
                        {
                            this.AddEmployeeToDataTable(this.dt, "Group", row3["GroupCode"].ToString());
                        }
                    }
                }
            }
            else if (MyLogin.Level == 2)
            {
                HRM_DEPARTMENT hrm_department2 = new HRM_DEPARTMENT();
                hrm_department2.Get(MyLogin.Code);
                this.dt.Rows.Add(new object[] { hrm_department2.DepartmentCode, hrm_department2.DepartmentName + this.StringQuantity(hrm_department2.FactQuantity, hrm_department2.Quantity), "", "Department", hrm_department2.FactQuantity, hrm_department2.Quantity, 2 });
                listByDepartment = new HRM_GROUP().GetListByDepartment(hrm_department2.DepartmentCode);
                foreach (DataRow row3 in listByDepartment.Rows)
                {
                    this.dt.Rows.Add(new object[] { row3["GroupCode"].ToString(), row3["GroupName"].ToString() + this.StringQuantity(row3), hrm_department2.DepartmentCode, "Group", int.Parse(row3["FactQuantity"].ToString()), int.Parse(row3["Quantity"].ToString()), 3 });
                    if (this.m_IsAll)
                    {
                        this.AddEmployeeToDataTable(this.dt, "Group", row3["GroupCode"].ToString());
                    }
                }
            }
            else
            {
                HRM_GROUP hrm_group2 = new HRM_GROUP();
                hrm_group2.Get(MyLogin.Code);
                this.dt.Rows.Add(new object[] { hrm_group2.GroupCode, hrm_group2.GroupName + this.StringQuantity(hrm_group2.FactQuantity, hrm_group2.Quantity), "", "Group", hrm_group2.FactQuantity, hrm_group2.Quantity, 3 });
                if (this.m_IsAll)
                {
                    this.AddEmployeeToDataTable(this.dt, "Group", hrm_group2.GroupCode);
                }
            }
            this.treeList1.DataSource = this.dt;
            this.treeList1.ExpandAll();
        }

        public void RaiseSelectedEventHander(Organization Item)
        {
            if (this.Selected != null)
            {
                this.Selected(this, Item);
            }
        }

        public void RaiseUpdatedEventHander()
        {
            if (this.Updated != null)
            {
                this.Updated(this);
            }
        }

        private void Reload()
        {
            if (this.m_IsAll)
            {
                this.LoadAllData();
            }
            else
            {
                this.LoadData(this.m_Status);
            }
        }

        public void SelectNodeByLevelCode(int Level, string Code)
        {
            foreach (TreeListNode node in this.treeList1.Nodes)
            {
                if ((int.Parse(node.GetValue("ImageIndex").ToString()) == Level) && (node.GetValue("ID").ToString() == Code))
                {
                    this.treeList1.SetFocusedNode(node);
                    break;
                }
                foreach (TreeListNode node2 in node.Nodes)
                {
                    if ((int.Parse(node2.GetValue("ImageIndex").ToString()) == Level) && (node2.GetValue("ID").ToString() == Code))
                    {
                        this.treeList1.SetFocusedNode(node2);
                        break;
                    }
                    foreach (TreeListNode node3 in node2.Nodes)
                    {
                        if ((int.Parse(node3.GetValue("ImageIndex").ToString()) == Level) && (node3.GetValue("ID").ToString() == Code))
                        {
                            this.treeList1.SetFocusedNode(node3);
                            break;
                        }
                        foreach (TreeListNode node4 in node3.Nodes)
                        {
                            if ((int.Parse(node4.GetValue("ImageIndex").ToString()) == Level) && (node4.GetValue("ID").ToString() == Code))
                            {
                                this.treeList1.SetFocusedNode(node4);
                                break;
                            }
                        }
                    }
                }
            }
        }

        public void SetFocusedNode(string code)
        {
            this.treeList1.SetFocusedNode(this.treeList1.FindNodeByFieldValue("ID", code));
        }

        private void ShowMenu(TreeListHitInfo hi, Point point)
        {
            DataRowView dataRecordByNode = (DataRowView) this.treeList1.GetDataRecordByNode(hi.Node);
            this.treeList1.SetFocusedNode(hi.Node);
            if (hi.Node != null)
            {
                if (dataRecordByNode["Type"].ToString() == "Company")
                {
                    this.ppCompany.ShowPopup(point);
                }
                else if (dataRecordByNode["Type"].ToString() == "Branch")
                {
                    this.ppBranch.ShowPopup(point);
                }
                else if (dataRecordByNode["Type"].ToString() == "Department")
                {
                    this.ppDepartment.ShowPopup(point);
                }
                else if (dataRecordByNode["Type"].ToString() == "Group")
                {
                    this.ppGroup.ShowPopup(point);
                }
                else if (dataRecordByNode["Type"].ToString() == "Employee")
                {
                    this.ppEmployee.ShowPopup(point);
                }
            }
        }

        private string StringQuantity(DataRow DataRow)
        {
            if (((this.m_Status == 0) || (this.m_Status == 1)) || (this.m_Status == 3))
            {
                return (" (" + DataRow["FactQuantity"].ToString() + "/" + DataRow["Quantity"].ToString() + ")");
            }
            if (this.m_Status == 2)
            {
                return (" (" + DataRow["FactQuantity"].ToString() + ")");
            }
            int num = int.Parse(DataRow["Quantity"].ToString()) - int.Parse(DataRow["FactQuantity"].ToString());
            return (" (" + num.ToString() + ")");
        }

        private string StringQuantity(int FactQuantity, int Quantity)
        {
            if (((this.m_Status == 0) || (this.m_Status == 1)) || (this.m_Status == 3))
            {
                return (" (" + FactQuantity.ToString() + "/" + Quantity.ToString() + ")");
            }
            if (this.m_Status == 2)
            {
                return (" (" + FactQuantity.ToString() + ")");
            }
            int num = Quantity - FactQuantity;
            return (" (" + num.ToString() + ")");
        }

        private void treeList1_FocusedNodeChanged(object sender, FocusedNodeChangedEventArgs e)
        {
            DataRowView dataRecordByNode = (DataRowView) this.treeList1.GetDataRecordByNode(e.Node);
            this.cls = new Organization();
            if (e.Node != null)
            {
                if (dataRecordByNode["Type"].ToString() == "Company")
                {
                    this.cls.Level = 0;
                    this.cls.Code = "";
                    this.RaiseSelectedEventHander(this.cls);
                }
                else if (dataRecordByNode["Type"].ToString() == "Branch")
                {
                    this.cls.BranchCode = dataRecordByNode["ID"].ToString();
                    this.cls.Code = dataRecordByNode["ID"].ToString();
                    this.cls.Level = 1;
                    this.RaiseSelectedEventHander(this.cls);
                }
                else if (dataRecordByNode["Type"].ToString() == "Department")
                {
                    this.cls.DepartmentCode = dataRecordByNode["ID"].ToString();
                    this.cls.Code = dataRecordByNode["ID"].ToString();
                    this.cls.Level = 2;
                    this.RaiseSelectedEventHander(this.cls);
                }
                else if (dataRecordByNode["Type"].ToString() == "Group")
                {
                    this.cls.GroupCode = dataRecordByNode["ID"].ToString();
                    this.cls.Code = dataRecordByNode["ID"].ToString();
                    this.cls.Level = 3;
                    this.RaiseSelectedEventHander(this.cls);
                }
                else if (dataRecordByNode["Type"].ToString() == "Employee")
                {
                    this.cls.EmployeeCode = dataRecordByNode["ID"].ToString();
                    this.cls.Level = 4;
                    this.RaiseSelectedEventHander(this.cls);
                }
            }
            this.treeList1.SetFocusedNode(e.Node);
        }

        private void treeList1_GetSelectImage(object sender, GetSelectImageEventArgs e)
        {
            DataRowView dataRecordByNode = (DataRowView) this.treeList1.GetDataRecordByNode(e.Node);
            e.NodeImageIndex = int.Parse(dataRecordByNode["ImageIndex"].ToString());
        }

        public void UpdateNodeByLevelCode(int Level, string Code)
        {
        }

        private void xucOrganization_Load(object sender, EventArgs e)
        {
        }

        private void xucOrganization_MouseDown(object sender, MouseEventArgs e)
        {
            this.m_Point = new Point(e.X, e.Y);
            if (e.Button == MouseButtons.Right)
            {
                this.ShowMenu(this.treeList1.CalcHitInfo(this.m_Point), this.treeList1.PointToScreen(this.m_Point));
            }
        }

        public delegate void SelectedEventHander(object sender, Organization Item);

        public delegate void UpdatedEventHander(object sender);
    }
}

